<template>
	<view class="page">
		<view class="nav_bar">
			<uni-nav-bar color="#333" left-icon="left" title="派单列表" :border='false' :fixed="true"
				background-color="transparent" @clickLeft="$util.back()"></uni-nav-bar>
		</view>
		
		<view class="nav_box"></view>
		
		<view class="container">
			<empty v-if="!list.length"></empty>
			
			<view class="list" v-for="(item,index) in list" :key="index">
				<view class="user flex_center">
					<view class="left flex_center">
						<view class="avatar">
							<image :src="item.avatar" mode="aspectFill"></image>
						</view>
						<view class="name">
							<view class="nickname flex_center">
								<text>{{ item.name }}({{ item.nickname }})</text>
								<image :src="$util.prefix('public/lf_owner_icon_v10_tech.png')" mode="aspectFill">
								</image>
							</view>
							
							<view class="mobile">{{ item.mobile }}</view>
						</view>
					</view>
					
					<view class="right flex_center">
						<image :src="$util.prefix('public/icon_jiaxiang.png')" mode="aspectFill"></image>
						<text>{{ item.juli_str }}</text>
					</view>
				</view>
			
				<view class="sign">
					{{ item.sign }}
				</view>
				
				<view class="btn flex_center">
					<view class="btn-item flex_r_around" @click="onDispatch(item,index)">
						<text>改派</text>
					</view>
				</view>
			
			</view>
		</view>
		
	</view>
</template>

<script>
	import empty from '@/compentents/empty/empty.vue';
	export default {
		components: {
			empty
		},
		data() {
			return {
				id: 0,
				
				lat: 0,
				lng: 0,
				circle_id: 0,
				store_id: 0,
				
				list: [],
				total: 1,
				page: 1,
			}
		},
		methods: {
			getList() {
				this.$get('/provider/getProviderList', {
					store_id: this.store_id,
					page: this.page,
					circle_id: this.circle_id,
					type: 2,
					lat: this.lat,
					lng: this.lng,
					show_store_self: 1,
				},false,()=>{
					uni.stopPullDownRefresh();
				}).then(res => {
					uni.stopPullDownRefresh();
					this.list.push(...res.data.data);
					this.total = res.data.total;
				});
			},
			
			refreshList(){
				this.page = 1;
				this.list = [];
				this.refreshList();
			},
			
			onDispatch(item,index){
				this.$post('store.order/dispatch',{
					order_id: this.id,
					provider_id: item.id
				}).then(res=>{
					this.$util.msg(res.msg);
					setTimeout(()=>{
						this.$util.back();
					},1000)
				})
			},
		},
		
		onLoad(option) {
			this.id = option.id;
			this.lat = option.lat;
			this.lng = option.lng;
			this.circle_id = option.circle_id;
			this.store_id = uni.getStorageSync('store').id || 0;
			this.getList();
		},
		
		onReachBottom() {
			if(this.total > this.list.length){
				this.page++;
				this.getList();
			}
		},
		
		onPullDownRefresh() {
			this.refreshList();
		},
	}
</script>

<style lang="less" scoped>
	.page {
		min-height: 100vh;
		background: #F1F1F1;
	}
	
	.nav_bar {
		background: #F1F1F1;
		background-size: 100%;
	
		/deep/ .uni-nav-bar-right-text {
			font-weight: 500;
			font-size: 30rpx;
			color: #FD2A53 !important;
		}
	}
	
	.container {
		padding: 0 24rpx 32rpx;
		
		.list {
			padding: 32rpx;
			background: #FFFFFF;
			border-radius: 24rpx;
			margin-bottom: 20rpx;
			
			.user {
				overflow: hidden;
				align-items: flex-start;
				.left {
					overflow: hidden;
					flex: 1;
					.avatar {
						flex-shrink: 0;
						width: 88rpx;
						height: 88rpx;
						background: #D8D8D8;
						border-radius: 44rpx;
						overflow: hidden;
						margin-right: 16rpx;
						image {
							width: 88rpx;
							height: 88rpx;
						}
					}
					
					.name {
						flex: 1;
						overflow: hidden;
						.nickname {
							text {
								font-weight: 500;
								font-size: 28rpx;
								color: #333333;
								max-width: 300rpx;
							}
							
							image {
								width: 32rpx;
								height: 32rpx;
								margin-left: 8rpx;
							}
						}
					
						.mobile {
							font-size: 24rpx;
							color: #999999;
							line-height: 34rpx;
							margin-top: 10rpx;
						}
					}
				}
				
				.right {
					image {
						width: 24rpx;
						height: 24rpx;
						margin-right: 8rpx;
					}
					
					text {
						font-size: 24rpx;
						color: #666666;
					}
				}
			}
		
			.sign {
				font-size: 24rpx;
				color: #666666;
				line-height: 34rpx;
				margin: 24rpx 0;
			}
			
			.btn {
				flex-direction: row-reverse;
				.btn-item {
					width: 168rpx;
					height: 64rpx;
					background: #FFFFFF;
					border-radius: 32rpx;
					border: 2rpx solid #CCCCCC;
					font-size: 28rpx;
					color: #131313;
				}
			}
		
		}
	}
	
</style>
